package com.ruoyi.studybase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.studybase.domain.StudyBase;
import com.ruoyi.studybase.service.IStudyBaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教育基地Controller
 * 
 * @author ruoyi
 * @date 2023-09-26
 */
@RestController
@RequestMapping("/studybase/studybase")
public class StudyBaseController extends BaseController
{
    @Autowired
    private IStudyBaseService studyBaseService;

    /**
     * 查询教育基地列表
     */
    @PreAuthorize("@ss.hasPermi('studybase:studybase:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudyBase studyBase)
    {
        startPage();
        List<StudyBase> list = studyBaseService.selectStudyBaseList(studyBase);
        return getDataTable(list);
    }

    /**
     * 导出教育基地列表
     */
    @PreAuthorize("@ss.hasPermi('studybase:studybase:export')")
    @Log(title = "教育基地", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudyBase studyBase)
    {
        List<StudyBase> list = studyBaseService.selectStudyBaseList(studyBase);
        ExcelUtil<StudyBase> util = new ExcelUtil<StudyBase>(StudyBase.class);
        util.exportExcel(response, list, "教育基地数据");
    }

    /**
     * 获取教育基地详细信息
     */
    @PreAuthorize("@ss.hasPermi('studybase:studybase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(studyBaseService.selectStudyBaseById(id));
    }

    /**
     * 新增教育基地
     */
    @PreAuthorize("@ss.hasPermi('studybase:studybase:add')")
    @Log(title = "教育基地", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudyBase studyBase)
    {
        return toAjax(studyBaseService.insertStudyBase(studyBase));
    }

    /**
     * 修改教育基地
     */
    @PreAuthorize("@ss.hasPermi('studybase:studybase:edit')")
    @Log(title = "教育基地", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudyBase studyBase)
    {
        return toAjax(studyBaseService.updateStudyBase(studyBase));
    }

    /**
     * 删除教育基地
     */
    @PreAuthorize("@ss.hasPermi('studybase:studybase:remove')")
    @Log(title = "教育基地", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(studyBaseService.deleteStudyBaseByIds(ids));
    }
}
